//
//  NearbyPhotos.m
//  PigMarket
//
//  Created by mac on 2019/6/12.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "NearbyPhotos.h"

@implementation NearbyPhotos

#pragma mark - init method
- (instancetype)init
{
    self = [super init];
    if (self) {
    }
    return self;
}

- (void)configPhotosWithImgsArr:(NSArray *)imgsArr {
    int count = (int)imgsArr.count;
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = 0;
    CGFloat h = 110 * [JTool getScreenWidthScale];
    
    if (count == 1) {
        w = SCREEN_WIDTH - 30 * [JTool getScreenWidthScale];
    } else if (count == 2) {
        w = (SCREEN_WIDTH - 39 * [JTool getScreenWidthScale]) / 2;
        
    }else if (count >= 3){
        w = (SCREEN_WIDTH - 48 * [JTool getScreenWidthScale]) / 3;
        count = 3;
    }
    for (int i = 0; i < count; i++) {
        x = i % count * (w + 9);
        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(x, y, w, h)];
        imgView.clipsToBounds = YES;
        imgView.contentMode = UIViewContentModeCenter;
        [imgView sd_setImageWithURL:[NSURL URLWithString:imgsArr[i]] placeholderImage:[UIImage imageNamed:@"placeholder_middle"]];
        [self addSubview:imgView];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imgTapped)];
        [imgView addGestureRecognizer:tap];
        imgView.userInteractionEnabled = YES;
    }
}
- (void)imgTapped {
    if (self.imgTappedBlock) {
        self.imgTappedBlock();
    }
}

@end
